//
//  WeiboTableView.m
//  Weibo
//
//  Created by taoshanchang on 15/1/30.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "WeiboTableView.h"
#import "WeiboCell.h"
#import "WeiboModel.h"
#import "CONSTS.h"

@implementation WeiboTableView

-(id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    self = [super initWithFrame:frame style:style];
    if(self){
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:kReloadTableNotification object:nil];
    }
    return self;
}

#pragma mark - tableView dataSourceDelegae
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identify = @"WeiboCell";
    WeiboCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if(cell == nil){ 
        cell = [[WeiboCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    }
    WeiboModel *weiboModel = [self.data objectAtIndex:indexPath.row];
    cell.weiboModel = weiboModel;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    WeiboModel *weiboModel = [self.data objectAtIndex:indexPath.row];
    float height = [WeiboView getWeiboViewHeight:weiboModel isRepost:NO isDetail:NO];
    height += 50;
    return height;

}



@end
